package com.rui.patterns.facade;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : SmartAppliancesFacade
 * @createTime : [2022/2/22 17:33]
 * @description : [外观类(用户主要和该类对象进行交互)]
 */

@SuppressWarnings("all")
public class SmartAppliancesFacade {

    /**
     * 聚合电灯，电视机，空调对象
     */
    private Light light;
    private TV tv;
    private AirCondition airCondition;

    public SmartAppliancesFacade() {
        this.light = new Light();
        this.tv = new TV();
        this.airCondition = new AirCondition();
    }

    /**
     * 通过语音控制
     * @param message 语音内容
     */
    public void say(String message){
        if(message.contains("打开")){
            //该方法可以控制所有家电的开启
            on();
        }else if(message.contains("关闭")){
            off();
        }else {
            System.out.println("我还听不懂你说的是什么");
        }
    }

    private void off() {
        this.light.off();
        this.tv.off();
        this.airCondition.off();
    }

    private void on() {
        this.light.on();
        this.tv.on();
        this.airCondition.on();
    }
}
